package arithmetic;

/**
 * 获取 一定范围内的 不重复几位随机数
 * @author: yyfei  
 * @email:  yyfei123@qq.com
 */
public class GetRepeatRandomNumber {
	public static void main(String[] args) {
		//获取几位随机数
		int len=6;
		int[] arr=new int[30];
		for (int i = 0; i < arr.length; i++) {
			arr[i]=i+1;
			//System.out.print(arr[i]+",");
		}
		
		getNum(arr,len);
	}
	
	/**
	 * arr 取值的范围数组
	 * len 获取的数的长度
	 * @author: yyfei
	 * @email:  yyfei123@qq.com
	 */
	public static int[] getNum(int[] arr,int len) {
		//定义返回新数组的长度
		int[] arrs=new int[len];
		//创建一个数组和arr一致
		boolean[] flog=new boolean[arr.length];
		for (int i = 0; i < flog.length; i++) {
		//System.out.print(flog[i]+",");
			for (int j = 0; j < len; j++) {
				if(!flog[i]) {
					arrs[j]=arr[i];	break;
				}	
			}
			flog[i]=true;
		}
		
		for (int i = 0; i < arrs.length; i++) {
			System.out.print(arrs[i]+",");
		}
		
		
		
		return arrs;
	}
	
	
}
